package raytracing

type HittableList struct {
	objects []Hittable
}

func NewHittableList() *HittableList {
	return &HittableList{
		objects: make([]Hittable, 0),
	}
}

func (hittableList *HittableList) Add(obj Hittable) {
	hittableList.objects = append(hittableList.objects, obj)
}

func (hittableList *HittableList) Hit(r *Ray, t_min float64, t_max float64, rec *HitRecord) bool {
	var tempRec HitRecord
	hit := false
	closestSoFar := t_max

	for _, obj := range hittableList.objects {
		if obj.Hit(r, t_min, closestSoFar, &tempRec) {
			hit = true
			closestSoFar = tempRec.T
			*rec = tempRec
		}
	}

	return hit
}
